home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / DataSource.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  10.9 KB  |  343 lines

  1. /*
  2.  * DataSource.java   1.0   12 Jan 1997
  3.  *
  4.  * Copyright (c) 1996 Krumel & Associates, Inc.  All Rights Reserved.
  5.  *
  6.  * This software is provided as is.  Krumel & Associates shall not be liable
  7.  * for any damages suffered by licensee as a result of using, modifying or
  8.  * distributing this software or its derivatives.
  9.  */
  10.  
  11. package symantec.itools.db.awt;
  12.  
  13. import java.awt.Image;
  14.  
  15. /**
  16.  * Interface defines the API required to support storing data for the Grid.<p>
  17.  *
  18.  * All row and column values are 0 relative.
  19.  */
  20. public interface DataSource {
  21.     /**
  22.      * Sets the Grid displaying the data.
  23.      */
  24.     public void setGrid(Grid v);
  25.  
  26.     /**
  27.      * Gets the grid displaying the data for the DataSource
  28.      */
  29.     public Grid getView();
  30.  
  31.     /**
  32.      * Informs the data source whether the grid will be requesting successive data
  33.      * for read only purposes.
  34.      * @param manual true if the data source should expect read only data requests
  35.      */
  36.     public void fetchMode(boolean manual);
  37.  
  38.     /**
  39.      * Sets the Data type for cell data when no data value has been set.
  40.      */
  41.     public void setDefaultData(Data defaultValue);
  42.  
  43.     /**
  44.      * Requests the DataSource set an appropriate default data type
  45.      */
  46.     public void setDefaultData();
  47.  
  48.     /**
  49.      * Gets whether the DataSource has the ability to configure a Grid
  50.      */
  51.     public boolean supportsMeta();
  52.  
  53.     /**
  54.      * Called by the Grid to configure the interface if the DataSource supports
  55.      * meta information
  56.      * @param v The grid to configure
  57.      * @exception   TypeNotSupported If the data source does not support the type of
  58.      *          action requested
  59.      */
  60.     public void setupGrid(Grid v) throws TypeNotSupported;
  61.  
  62.     /**
  63.      * Requests the current data element be reset to the previously committed
  64.      * state
  65.      */
  66.     public void rollbackCurrentData();
  67.  
  68.     /**
  69.      * Gets the data for a cell that should only be used for reading. It does
  70.      * not change the cell data being currently edited.
  71.      * @param row the cells row
  72.      */
  73.     public Data readData(int row, int col) throws DataNotAvailable;
  74.  
  75.     /**
  76.      * Gets the data for a cell.  If the requested data is not the data being
  77.      * currently edited, the current data should be set to the data requested
  78.      */
  79.     public Data getData(Coordinate coords) throws DataNotAvailable;
  80.  
  81.     /**
  82.      * Gets the data for a cell.  If the requested data is not the data being
  83.      * currently edited, the current data should be set to the data requested
  84.      */
  85.     public Data getData(int r, int c) throws DataNotAvailable;
  86.  
  87.     /**
  88.      * Commits the current data.
  89.      * @exception   TypeNotSupported If the data source does not support the type of
  90.      *          action requested or is not successful
  91.      */
  92.     public void commitData() throws TypeNotSupported;
  93.  
  94.     /**
  95.      * Sets the data value for a cell.
  96.      * @param r the row of the cell
  97.      * @param c the column of the cell
  98.      * @param data the data value for the cell
  99.      * @exception   TypeNotSupported If the data source does not support the type of
  100.      *          action requested or is not successful
  101.      */
  102.     public void setData(int r, int c, Data data) throws TypeNotSupported;
  103.  
  104.     /**
  105.      * Sets the data value for a cell.
  106.      * @param coord the cooridates of the cell
  107.      * @param data the data value for the cell
  108.      * @exception   TypeNotSupported If the data source does not support the type of
  109.      *          action requested or is not successful
  110.      */
  111.     public void setData(Coordinate coord, Data data) throws TypeNotSupported;
  112.  
  113.     /**
  114.      * Gets the textual representation of a cell's data
  115.      * @exception   DataNotAvailable The requested data is not set in the
  116.      *          data source.
  117.      */
  118.     public String getText(Coordinate coords) throws DataNotAvailable;
  119.  
  120.     /**
  121.      * Gets an image representation of a cell's data
  122.      * @exception   DataNotAvailable The requested data is not set in the
  123.      *          data source.
  124.      */
  125.     public Image getImage(Coordinate coords) throws DataNotAvailable;
  126.  
  127.     /**
  128.      * Deletes or marks a row for deletion from the data source
  129.      * @exception   TypeNotSupported If the data source does not support the type of
  130.      *          action requested or is not successful
  131.      */
  132.     public void deleteRow(int row) throws TypeNotSupported;
  133.  
  134.     /**
  135.      * Undeletes a row in the data source
  136.      * @exception   TypeNotSupported If the data source does not support the type of
  137.      *          action requested or is not successful
  138.      */
  139.     public void undeleteRow(int row) throws TypeNotSupported;
  140.  
  141.     /**
  142.      * Inserts a new row in the data source above the specified row
  143.      * @exception   TypeNotSupported If the data source does not support the type of
  144.      *          action requested or is not successful
  145.      */
  146.     public void insertRow(int row) throws TypeNotSupported;
  147.  
  148.     /**
  149.      * Appends a new row at the end of the data source's data.
  150.      */
  151.     public int appendRow() throws TypeNotSupported;
  152.  
  153.     /**
  154.      * Gets whether the data source supports a specified type of data
  155.      */
  156.     public boolean supports(Coordinate coords, int type);
  157.  
  158.     /**
  159.      * Called in response to circulating an event caused by an invocation of
  160.      * Grid.generateEvent().  The event IDs are specified in the Grid class
  161.      * @return true if the event is handled by the data source.
  162.      */
  163.     public boolean handleEvent(java.awt.Event e);
  164.  
  165.     /**
  166.      * Routes any exceptions generated to the Grid for proper handling which may
  167.      * include putting a message on status bar or logging to a file.
  168.      */
  169.     public void handleException(int row, int col, Exception ex);
  170.  
  171.     /**
  172.      * Requests the data source reread it data.
  173.      */
  174.     public void refresh();
  175.  
  176.     /**
  177.      * Requests the data source remove all data.
  178.      */
  179.     public void clear();
  180.  
  181.     /**
  182.      * Requests the data source save the current state as appopriate.
  183.      */
  184.     public void save() throws TypeNotSupported;
  185.  
  186.     /**
  187.      * Requests that any actions performed on a row be undone. The meaning
  188.      * is left open and is to interpreted as appropriate for the type of
  189.      * data source
  190.      */
  191.     public void undoRow(int row) throws TypeNotSupported;
  192.  
  193.     /**
  194.      * Gets whether a cells data is editable or non-editable
  195.      * @return true if the data may be altered by the user.
  196.      */
  197.     public boolean isDataEditable(int row, int col);
  198.  
  199.     /**
  200.      * Informs the data source of the current row of the Grid.
  201.      */
  202.     public void setCurrentRow(int row) throws TypeNotSupported;
  203.  
  204.     /**
  205.      * The state of the row is new
  206.      */
  207.     public static final int NEW_ROW = 0;
  208.     /**
  209.      * The state of the row is clean (it has been been changed since loaded
  210.      * from some source)
  211.      */
  212.     public static final int CLEAN_ROW = 1;
  213.     /**
  214.      * The row has been marked for deletion.
  215.      */
  216.     public static final int DELETED_ROW = 2;
  217.     /**
  218.      * The row has been modified since creation.
  219.      */
  220.     public static final int MODIFIED_ROW = 3;
  221.  
  222.     /**
  223.      * Gets the state of the row.
  224.      * @return the state of the row's data. One of NEW_ROW, CLEAN_ROW, DELETED_ROW,
  225.      *          or MODIFIED_ROW
  226.      */
  227.     public int rowState(int row);
  228.  
  229.     /**
  230.      * Gets the last row valid in requested range
  231.      * @exception   DataNotAvailable The requested data is not set in the
  232.      *          data source.
  233.      */
  234.     public int validDataRowRange(int top, int bottom) throws DataNotAvailable;
  235.  
  236.     /**
  237.      * Gets the number of rows of data stored in the data source
  238.      */
  239.     public int rows();
  240.  
  241.     /**
  242.      * Requests the data source get all of the rows from its source of data.
  243.      */
  244.     public int fetchAllRows();
  245.  
  246.     //Here are some methods needed to support DefaultData
  247.     /**
  248.      * Method used to support Defaultdata class. Gets the type of data supported
  249.      * by the cell.
  250.      */
  251.     public int type(int row, int col);
  252.  
  253.     /**
  254.      * Method used to support Defaultdata class. Commits the data for the
  255.      * specified cell
  256.      */
  257.     public void commit(int row, int col) throws TypeNotSupported;
  258.  
  259.     /**
  260.      * Method used to support Defaultdata class. Gets whether the data for the
  261.      * specified cell supports choice selection lists.
  262.      */
  263.     public boolean supportsChoice(int row, int col);
  264.  
  265.     /**
  266.      * Method used to support Defaultdata class. Gets the choices for the cell to
  267.      * display.
  268.      */
  269.     public Data[] getChoices(int row, int col) throws TypeNotSupported;
  270.  
  271.     /**
  272.      * Method used to support Defaultdata class. Sets the textual value for a cell.
  273.      */
  274.     public void setText(int row, int col, String t);
  275.     //pos is space where to be inserted (0 = first char)
  276.  
  277.     /**
  278.      * Method used to support Defaultdata class. Inserts a character at the
  279.      * specified location in the data value for a cell.
  280.      * @param row The cell's row
  281.      * @param col The cell's column
  282.      * @param pos The position to insert character
  283.      * @param c The character
  284.      */
  285.     public void insertChar(int row, int col, int pos, char c);
  286.  
  287.     /**
  288.      * Method used to support Defaultdata class. Sets the text for a cell to a
  289.      * character
  290.      */
  291.     public void setText(int row, int col, char c);
  292.  
  293.     /**
  294.      * Method used to support Defaultdata class.  Appends a character to the end
  295.      * of the textual representation of the cell's data.
  296.      */
  297.     public void appendChar(int row, int col, char c);
  298.  
  299.     /**
  300.      * Method used to support Defaultdata class. Clears the textual value of a cell.
  301.      */
  302.     public void clearText(int row, int col);
  303.  
  304.     /**
  305.      * Method used to support Defaultdata class. Deletes a character from a cell's
  306.      * data.
  307.      * @param row The cell's row
  308.      * @param col The cell's column
  309.      * @param pos The position to delete character
  310.      */
  311.     public void deleteChar(int row, int col, int pos);
  312.  
  313.     /**
  314.      * Method used to support Defaultdata class. Gets a substring from a cell's
  315.      * data.
  316.      * @param row The cell's row
  317.      * @param col The cell's column
  318.      * @param spos The starting position of the substring, inclusive
  319.      * @param epos The last position of the substring, exclusive
  320.      */
  321.     public String subString(int row, int col, int spos, int epos);
  322.  
  323.     /**
  324.      * Method used to support Defaultdata class. Sets the image data for a cell
  325.      */
  326.     public void setImage(int row, int col, Image i);
  327.  
  328.     /**
  329.      * Method used to support Defaultdata class. Gets a string representation of
  330.      * a cell's data.
  331.      */
  332.     public String toString(int row, int col);
  333.  
  334.     /**
  335.      * Method used to support Defaultdata class. Gets an image representationof
  336.      * a cell's data.
  337.      */
  338.     public Image toImage(int row, int col);
  339.  
  340.     public Object getSynchronizationObject();
  341. }
  342.  
  343.